import java.util.Scanner;

public class NGuessNumber {

    public static int[] generateAnswer() {
        int[] arr = new int[4];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) (Math.random() * 9 + 1);
        }
        for (int j = 1; j < arr.length; j++) {
            for (int i = 0; i < j; i++) {
                if (arr[j] == arr[i]) {
                    arr[j] = (int) (Math.random() * 9);
                    j--;
                }
            }
        }
        return arr;
    }

    public static int[] getPlayerInput(){
        Scanner scanner = new Scanner(System.in);
        int[] arr = new int[4];
        for(int temp = 0;temp < arr.length;temp++){
            arr[temp] = scanner.nextInt();
        }
        return arr;
    }

    public static String compareGuessAnswer(int[] numbers, int[] guesslist) {
        int A = 0;
        int B = 0;
        for (int i = 0; i < numbers.length; i++) {
            for (int l = 0; l < numbers.length; l++) {
                if (i != l) {
                    if (numbers[i] == guesslist[l]) {
                        B++;
                    }
                } else {
                    if (numbers[i] == guesslist[l]) {
                        A++;
                    }
                }

            }
        }
        System.out.println(A + "A" + B + "B");
        return A + "A" + B + "B";
    }

    public static boolean isWin(String jg){
        return jg.equals("4A0B") || jg.equals("3A1B");
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(true){
            System.out.println("是否开始游戏(y/n)");
            String is = scanner.next();
            boolean isWin = false;
            if(!is.equals("y")){
                break;
            }
            int[] answer = generateAnswer();
            for(int count = 0;count < 7;count++){
                System.out.println("你还有"+(7-count)+"次机会");
                int[] input = getPlayerInput();
                if(isWin(compareGuessAnswer(input,answer))){
                    System.out.println("你赢了");
                    break;
                }else{
                    System.out.println("猜错了,再试一次吧");
                }
            }
        }
        System.out.println("谢谢游玩");

    }
}
